package demo2;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/p1")
public class PathCtrl {
    @RequestMapping("/m1")
    public void m1(){
        System.out.println("m1");
    }

    @RequestMapping("/m2")
    public String m2(){
        return "success";
    }

    @RequestMapping("/m3/*")
    public void m3(){
        System.out.println("m3....");

    }

    @RequestMapping("/m4/**")
    public void m4(){
        System.out.println("m4....");

    }
    @RequestMapping("/m5/?")
    public void m5(){
        System.out.println("m5....");

    }

    //localhost/p1/m6/1/abc
    @RequestMapping("/m6/{id}/{name}")
//必须给形参上添加@PathVariable注解
    public void m6(@PathVariable String id, @PathVariable("name") String n){
        System.out.println("m6xxx,id="+id+",name="+n);
    }

    @RequestMapping("/m7/{id:\\d+}/{name}")
    public void m7(@PathVariable String id,@PathVariable("name") String n){
        System.out.println("m6xxx,id="+id+",name="+n);
    }


    //同一url多种handler
    //@RequestMapping(path="/m8/{id:\\d+}" ,method= RequestMethod.GET)
    @GetMapping("/m8/{id:\\d+}" )
    public String m8(@PathVariable String id,@PathVariable(required = false) String n){
        System.out.println("m8xxx,id="+id+",name="+n);
        return "success";
    }
    @PostMapping("/m8/{id:\\d+}" )
    public void m9(@PathVariable String id,@PathVariable(required = false) String n){
        System.out.println("m9xxx,id="+id+",name="+n);
    }


    /*同一个资源，多种路径*/
    @RequestMapping(path={"/r8","/test8"})
    public void m8() {
        System.out.println("多个url访问同一个handler");
    }
}
